define(function(require, exports){
	var pubjs = require('pubjs');
	var view = require('@base/view');
	var $ = require('jquery');
	var util = require('util');
	var dialog = require('@base/dialog').base;

	var DomainImport = view.widget.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"module": dialog,
					"title": LANG('导入域名'),
					"silence": false,
					"buttonConfig": {
						"ok": {
							"value": LANG('确定')
						}
					},
					'size': 'l'
				},
				'view_model': {
					domain: ''
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();

			el.append($([
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('请输入域名：') + '</label>',
					'<div class="group-content">',
						'<textarea ms-duplex="domain" rows="10" cols="70" placeholder="'+ LANG('以http://或https://开头，输入多个时，换行隔开。') +'"/>',
					'</div>',
				'</div>'
			].join('')));
		}
		,getValue: function(){
			var vm = this.vm.$;
			var cs = this.$;
			var domain = [];
			var value = vm.domain.split('\n');
			// this.vm.set('domain','');
			vm.domain = ""
			value.forEach(function(item){
				var trimItem = util.trim(item);
				if (trimItem) {
					domain.push({'Content': trimItem});
				}
			});

			return domain;
		}
		// ,setValue: function(data){
		// 	var vm = this.vm.$;
		// 	var cs = this.$;
		// 	vm.domain = data.ids.join('\n') || '';

		// 	return this;
		// }
		,validate: function(data){
			if (!data.length) {
				pubjs.alert(LANG('请输入域名！'));
				return false;
			}
			return true;
		}
		,onDialogOk: function(){
			var self = this;
			var data = self.getValue();
			var saveUrl = this.getConfig('saveUrl');
			if (self.validate(data)) {
				this.fire('adImportOk', data);
				this.hide();
			}
			return false;
		}
	});

	exports.domainImport = DomainImport;

	var AppidImport = view.widget.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'layout': {
					"module": dialog,
					"title": LANG('导入APPID'),
					"silence": false,
					"buttonConfig": {
						"ok": {
							"value": LANG('确定')
						}
					},
					'size': 'l'
				},
				'view_model': {
					appid: ''
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild: function(){
			var self = this;
			var el = self.getDOM();

			el.append($([
				'<div class="M-formConGroup">',
					'<label class="group-label">' + LANG('请输入APPID：') + '</label>',
					'<div class="group-content">',
						'<textarea ms-duplex="appid" rows="10" cols="70" placeholder="'+ LANG('输入多个时，换行隔开。') +'"/>',
					'</div>',
				'</div>'
			].join('')));
		}
		,getValue: function(){
			var vm = this.vm.$;
			var cs = this.$;
			var appid = [];
			var value = vm.appid.split('\n');
			// this.vm.set('appid','');
			vm.appid = ""
			value.forEach(function(item){
				var trimItem = util.trim(item);
				if (trimItem) {
					appid.push({'Content': trimItem});
				}
			});

			return appid;
		}
		// ,setValue: function(data){
		// 	var vm = this.vm.$;
		// 	var cs = this.$;
		// 	vm.appid = data.ids.join('\n') || '';

		// 	return this;
		// }
		,validate: function(data){
			if (!data.length) {
				pubjs.alert(LANG('请输入APPID！'));
				return false;
			}
			return true;
		}
		,onDialogOk: function(){
			var self = this;
			var data = self.getValue();
			var saveUrl = this.getConfig('saveUrl');
			if (self.validate(data)) {
				this.fire('adImportOk', data);
				this.hide();
			}
			return false;
		}
	});

	exports.appidImport = AppidImport;
});